<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: blueviolet;
            margin: 0 auto;

        }
    </style>
</head>
<body>
    <div>

    </div>
    <!-- 
        闭包的作用就是延申了一个变量做作用域
        多用与函数的嵌套
     -->
    <script>
        (function(){
            var a=1;  //全局
            document.querySelector('div').onclick=function()
            {
                this.innerText=a
                a++
            }
        })();
        

    </script>

</body>
</html>